from flask import request

from factort_flask import crea_flask_app
# from settings import DefaultConfig
import json
app = crea_flask_app()

# @app.route("/",)
# def index():
#     print(app.config.get('MYSQL_DATABASE'),
#           app.config.get('MYSQL_USER'),
#           app.config.get('MYSQL_PASSWORD'),
#           app.config.get('MYSQL_HOST'),
#           app.config.get('MYSQL_PORT'),
#           app.config.get('MYSQL_CHARSET'))
#     return '1111'

class_data = app.config.get('CLASS_LIST')
student_data = app.config.get('STUDENT_LIST')
#获取所有的班级信息
@app.route('/classes',methods=['GET'])
def class_list():
    ser = json.dumps(class_data)
    return ser
#获取该班级下的学生信息
@app.route('/stu/<class_name>',methods=['GET'])
def stu_list(class_name):
    temp = []
    for i in student_data:
        if i.get('classes') == class_name:
            temp.append(i)
    ser = json.dumps(temp)
    return ser
#修改学生信息
@app.route('/stu/<int:stu_id>',methods=['PUT'])
def stu(stu_id):
    for i in student_data:
        if i['id'] == stu_id:
            i['name'] = request.args.get('name1')
    data = {'data':student_data}

    return json.dumps(data)

@app.route('/student',methods=['GET'])
def student():
    print(student_data)
    return '111'




if __name__ == '__main__':
    app.run()